﻿using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

//
using pendina.transceiver.framework;

namespace pendina.framework.test
{
    class Program
    {
        static void Main(string[] args)
        {
            Timer myTimer = new Timer(3000);
            transceiver_core cs = new transceiver_core();
            cs.start();


            while (true)
            {
                System.Threading.Thread.Sleep(1);
                var str = cs.update();
                if (str != null)
                {
                    using (BinaryReader reader = new BinaryReader(str))
                    {
                        int code = reader.ReadInt32();
                        switch (code)
                        {
                            case 1:
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_CONNECT " + @code);
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_CONNECT ID:" + reader.ReadInt32());
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_CONNECT HOST:" + reader.ReadInt32());
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_CONNECT PORT:" + reader.ReadInt32());
                                Console.Error.WriteLine("--> ");
                                break;
                            case 2:
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_DISCONNECT " + @code);
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_DISCONNECT " + reader.ReadInt32());
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_DISCONNECT " + reader.ReadInt32());
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_DISCONNECT " + reader.ReadInt32());
                                break;
                            case 3:
                                var count = reader.ReadInt32();
                                var data = reader.ReadChars(count);

                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_RECEIVE " + @code);
                                Console.Error.WriteLine("--> ENET_EVENT_TYPE_RECEIVE BYTES:" + @count);
                                for(int i=0;i<data.Length;i++)
                                Console.Error.Write(data[i]);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }

            Console.ReadLine();
            cs.stop();
        }
    }
}
